// pages/mySelf/Index/index.js
var common = require("../../../../../public.js");
var HttpUrl = common.HttpUrl
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: [],
    token: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.getStorage({
      key: 'user',
      success: function (res) {
        console.log(res)
        that.setData({
          userInfo: res.data.user,
          token: res.data.token,
        }, () => { that.getActList() })
      }
    })

  },
  getActList() {
    var that = this;
    console.log(that.data.userInfo.id)
    wx.request({
      url: HttpUrl + '/activity/selectByUser',
      data: {
        userId: that.data.userInfo.id
      },
      method: "GET",
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        console.log(res.data.data.result_list)
        that.setData({
          actData: res.data.data.result_list,
        }, () => {
          that.convertTime(that.data.actData) //调用时间控件
        })
      }
    })
  },
  convertTime(time) {
    const tba = time.map((item, index) => {
      const holdingStarttime = this.time(item.holdingStarttime);
      const tabs = {
        id: item.id,
        title: item.title,
        holdingStarttime: holdingStarttime,
        holdingAddress: item.holdingAddress
      }
      return tabs;
    })
    this.setData({
      actData: tba
    })
  },
  time(time) {
    var now = new Date(time);
    var year = now.getFullYear();
    var month = now.getMonth() + 1;
    var day = now.getDate();
    var hours = now.getHours();
    var minutes = now.getMinutes();
    if (month <= 9) month = '0' + month;
    if (day <= 9) day = '0' + day;
    if (hours <= 9) hours = '0' + hours;
    if (minutes <= 9) minutes = '0' + minutes;
    var shu = year + '-' + month + '-' + day + ' ' + hours + ':' + minutes;
    return shu;
  }
})